package com.shop.clientorder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.shop.car.domain.ShopCarDetails;
import com.shop.clientorder.domain.*;
import com.shop.common.security.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shop.common.log.annotation.Log;
import com.shop.common.log.enums.BusinessType;
import com.shop.common.security.annotation.RequiresPermissions;
import com.shop.clientorder.service.IOmsOrderService;
import com.shop.common.core.web.controller.BaseController;
import com.shop.common.core.domain.Result;
import com.shop.common.core.utils.poi.ExcelUtil;


/**
 * 订单Controller
 *
 * @author czb
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/clientorder")
public class OmsOrderController extends BaseController
{
    @Autowired
    private IOmsOrderService omsOrderService;

    @Autowired
    private TokenService tokenService;

///**
// * 查询订单列表
// */
//@RequiresPermissions("clientorder:clientorder:list")
//@GetMapping("/list")
//    public Result list(OmsOrder omsOrder)
//    {
//        startPage();
//        List<OmsOrder> list = omsOrderService.selectOmsOrderList(omsOrder);
//        return getDataTable(list);
//    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("clientorder:clientorder:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsOrder omsOrder)
    {
        List<OmsOrder> list = omsOrderService.selectOmsOrderList(omsOrder);
        ExcelUtil<OmsOrder> util = new ExcelUtil<OmsOrder>(OmsOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("clientorder:clientorder:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(omsOrderService.selectOmsOrderById(id));
    }

    /**
     * 跳转订单生成页面
     */
//    @RequiresPermissions("clientorder:clientorder:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody OrderVo orderVo)
    {
        List<ShopCarDetails> shopCarDetails = omsOrderService.insertOmsOrder(orderVo);
        return Result.success(shopCarDetails);
    }

    @GetMapping("/fullAdders")
    public Result<List<FullAdders>> fullAdders(){
        startPage();
        Long userId = tokenService.getLoginUser().getSysUser().getUserId();
        List<FullAdders> list = omsOrderService.fullAdders(userId);
        return Result.success(list);
    }

//    /**
//     * 新增订单
//     */
////    @RequiresPermissions("clientorder:clientorder:add")
//    @Log(title = "订单", businessType = BusinessType.INSERT)
//    @PostMapping("new")
//    public Result addOrder(@RequestBody OrderItemRequest orderItemRequest)
//    {
//        return toAjax(omsOrderService.insertOmsOrderNew(orderItemRequest));
//    }


    /**
     * 修改订单
     */
    @RequiresPermissions("clientorder:clientorder:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody OmsOrder omsOrder)
    {
        return toAjax(omsOrderService.updateOmsOrder(omsOrder));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("clientorder:clientorder:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(omsOrderService.deleteOmsOrderByIds(ids));
    }



    /**
     * 查询订单列表
     */
    @RequiresPermissions("clientorder:clientorder:list")
    @GetMapping("/list")
    public Result OmsOrderList(OrderReq orderReq)
    {
        startPage();
        List<OmsOrder> list = omsOrderService.selectClirentOrderList(orderReq);
        return getDataTable(list);
    }

}
